package search;
//https://leetcode.cn/leetbook/read/illustration-of-algorithm/5v76yi/
public class LCR_121寻找目标值_二维数组 {
    //二叉搜索树
    class Solution {
        public boolean findTargetIn2DPlants(int[][] plants, int target) {
            if(plants == null) return false;
            int i = plants.length - 1, j = 0;
            while (i >= 0 && j < plants[0].length){
                if(plants[i][j] < target) j++;
                else if(plants[i][j] > target) i--;
                else return true;
            }
            return false;
        }
    }
    //暴力
    class Solution2 {
        public boolean findTargetIn2DPlants(int[][] plants, int target) {
            if(plants == null) return false;
            for(int i = 0;i< plants.length;i++){
                for(int j = 0;j < plants[0].length;j++)
                    if(plants[i][j] == target)
                        return true;
            }
            return false;
        }
    }
}
